 

package com.zdkj.subway.stm.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.constant.CommonConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.stm.dto.in.QueryContionDTO;
import com.zdkj.subway.stm.entity.SwStPackageRecordManage;
import com.zdkj.subway.stm.entity.SwStPackageTailboxManage;
import com.zdkj.subway.stm.service.SwStPackageRecordManageService;
import com.zdkj.subway.stm.util.BeanUtilsStm;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 库包记录管理
 *
 * @author songtuo
 * @date 2020-03-07 14:36:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swstpackagerecordmanage" )
@Api(value = "swstpackagerecordmanage", tags = "库包记录管理")
public class SwStPackageRecordManageController {

    private final  SwStPackageRecordManageService swStPackageRecordManageService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param swStPackageRecordManage 库包记录管理
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwStPackageRecordManagePage(Page page, SwStPackageRecordManage swStPackageRecordManage, QueryContionDTO queryContionDTO) {
        swStPackageRecordManage.setDelFlag(CommonConstants.STATUS_DEL);
        //按照上交库包时间进行时间筛选
        QueryWrapper<SwStPackageRecordManage> query = BeanUtilsStm.addTimeContiontion(swStPackageRecordManage, queryContionDTO, "HAND_PACKAGE_TIME");
        return R.ok(swStPackageRecordManageService.page(page, query));
    }


    /**
     * 通过id查询库包记录管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(swStPackageRecordManageService.getById(id));
    }

    /**
     * 新增库包记录管理
     * @param swStPackageRecordManage 库包记录管理 equipment
     * @return R
     */
    @ApiOperation(value = "新增库包记录管理", notes = "新增库包记录管理")
    @SysLog("新增库包记录管理" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('swstpackagerecordmanage_add')" )
    public R save(@RequestBody SwStPackageRecordManage swStPackageRecordManage) {
        SwStPackageRecordManage defaultObj = ObjectUtils.getDefaultObj(SwStPackageRecordManage.class);
        BeanUtil.copyProperties(defaultObj, swStPackageRecordManage, CopyOptions.create().setIgnoreNullValue(true));
        return R.ok(swStPackageRecordManageService.save(swStPackageRecordManage));
    }

    /**
     * 修改库包记录管理
     * @param swStPackageRecordManage 库包记录管理
     * @return R
     */
    @ApiOperation(value = "修改库包记录管理", notes = "修改库包记录管理")
    @SysLog("修改库包记录管理" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('swstpackagerecordmanage_edit')" )
    public R updateById(@RequestBody SwStPackageRecordManage swStPackageRecordManage) {
        return R.ok(swStPackageRecordManageService.updateById(swStPackageRecordManage));
    }

    /**
     * 通过id删除库包记录管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除库包记录管理", notes = "通过id删除库包记录管理")
    @SysLog("通过id删除库包记录管理" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('swstpackagerecordmanage_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(swStPackageRecordManageService.removeById(id));
    }

}
